package org.erepublik.company.controllers;

import java.util.Arrays;

import org.erepublik.company.PriceIndex;
import org.erepublik.company.comparators.InvertPriceSort;
import org.erepublik.company.searchCriteria.EMovingDistance;
import org.erepublik.company.searchCriteria.TicketPriceSearchCriteria;
import org.erepublik.company.service.PriceIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/ticketPricesHistory.html")
public class TicketPricesHistoryController extends AbstractController {
    
    
    @RequestMapping(method = RequestMethod.GET)
    public String showForm(ModelMap model) {
        fillModelMap(model);
        PriceIndex[] prices = countryDataService.getPricesIndex("ticket", EMovingDistance.ZONE4);
        Arrays.sort(prices, new InvertPriceSort());
 
        model.addAttribute("prices", prices);
        model.addAttribute("priceTicketSearchCriteria", new TicketPriceSearchCriteria());
        return "ticketPricesHistory";
    }
    
    
    @RequestMapping(method = RequestMethod.POST)
    public String showList(ModelMap model, @ModelAttribute("TicketFoodSearchCriteria") TicketPriceSearchCriteria criteria) {
        fillModelMap(model);
        PriceIndex[] prices = countryDataService.getPricesIndex("ticket", criteria.getMovingDistance());
        Arrays.sort(prices, new InvertPriceSort());
        
        model.addAttribute("prices", prices);
        model.addAttribute("priceTicketSearchCriteria", criteria);
        return "ticketPricesHistory";
    }
    

    
}
